//
//  UIView+DefinedAnimation.m
//  TravelGuideMdd
//
//  Created by 刘澈 on 14-8-5.
//  Copyright (c) 2014年 mafengwo.com. All rights reserved.
//

#import "UIView+DefinedAnimation.h"

#define SCALE 2.2f



@implementation UIView (DefinedAnimation)


#pragma mark - 抽离出闪烁动画的方法
-(void)flickerAnimation:(ExcuteBlock)excuteBlock complete:(CompleteBlock)completeBlock{
    UIGraphicsBeginImageContext(self.frameSize); //currentView 当前的view
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
   __block UIImageView* imageView = [[UIImageView alloc] initWithImage:viewImage];
    imageView.frame = self.frame;
    UIView *fatherView = self.superview;
    if(fatherView == nil){
        return;
    }
    [fatherView addSubview:imageView];
    __weak UIView *wself = self;
    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        wself.userInteractionEnabled = NO;
        imageView.layer.transform =CATransform3DMakeScale(2.0, 2.0, 2.0);
        imageView.alpha = 0;
        excuteBlock();
    } completion:^(BOOL f){
        self.userInteractionEnabled = YES;
        [imageView removeFromSuperview];
        imageView = nil;
        completeBlock();
    }];
}


-(void)scaleAnimation:(ExcuteBlock)excuteBlock complete:(CompleteBlock)completeBlock{
    __weak UIView *wself = self;
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        wself.transform = CGAffineTransformScale(wself.transform, SCALE,SCALE);
        excuteBlock();
    } completion:^(BOOL finished){
        [UIView animateWithDuration:0.2 animations:^(){
            wself.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished){
            completeBlock();
        }];
    }];
}



@end
